import java.net.InetAddress;
import java.net.UnknownHostException;

public class TestIP {

    public static void main(String[] args) throws UnknownHostException {
        // 1.获取本机ip地址对象
        InetAddress ip1 = InetAddress.getLocalHost();
        System.out.println(ip1);
        System.out.println(ip1.getHostAddress());

        // 2.获取域名ip对象
        InetAddress ip2 = InetAddress.getByName("www.baidu.com");
        System.out.println(ip2);
        System.out.println(ip2.getHostName());
        System.out.println(ip2.getHostAddress());
    }
}
